package com.ll.springai.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ai")
class AIController {

    @Autowired
    private OllamaChatModel ollamaChatModel;

    @GetMapping("/chat")
    public String chat(@RequestParam(value = "msg", defaultValue = "给我讲个笑话") String msg) {
        ChatClient chatClient = ChatClient.create(ollamaChatModel);
        //prompt:提示词
        return chatClient.prompt()
            //用户输入的信息
            .user(msg)
            //请求大模型
            .call()
            //返回文本
            .content();
    }
}
